package set_;

import java.util.HashSet;
import java.util.Objects;

/**
 * @Author 小闽
 * @Date 2024/11/3 23:06
 * @PackageName: set_
 * @ClassName: HashSetExercise02
 * @Description:
 * @Version
 */
@SuppressWarnings({"all"})
public class HashSetExercise02 {
    public static void main(String[] args) {
        /**
         * 定义一个Employee类，该类包含：private成员属性name,sal,birthday(MyDate类型)，其中birthday为MyDate类型
         * （属性包括：year,month,day），要求：
         * 1. 床架你3个Employee放入HashSet中
         * 2. 当name和birthday的值相同时，认为是相同员工，不能添加到HashSet集合中
         */
        HashSet hashSet = new HashSet();
        Employee01 jack = new Employee01("jack", 2000, new MyDate(2000, 11, 10));
        Employee01 tom = new Employee01("tom", 3000, new MyDate(2001, 12, 10));
        Employee01 simth = new Employee01("jack", 1000, new MyDate(2000, 11, 10));
        hashSet.add(jack);
        hashSet.add(tom);
        hashSet.add(simth);
        System.out.println("hashSet= " + hashSet);

    }
}
class MyDate{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year &&
                month == myDate.month &&
                day == myDate.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }
}
class Employee01{
    private String name;
    private double sal;
    private MyDate birthday; // 定义birthday为MyDate类型

    public Employee01(String name, double sal,MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    @Override
    public String toString() {
        return "Employee01{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee01 that = (Employee01) o;
        return name.equals(that.name) &&
                birthday.equals(that.birthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, birthday);
    }
}